//
//  MenuHeaderView.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/27.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "MenuDetailListCell.h"

#import "MenuHeaderView.h"
#import "MenuSectionHeader.h"

@interface MenuHeaderView ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) MenuSectionHeader *sectionHeaderView;

@end

@implementation MenuHeaderView

+ (CGFloat)calculateHeader {
    
    CGFloat height = (TTScreenWidth - 30)*1.902;
    return height;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    [self initView];
    
    [self.imageBGView sd_setImageWithURL:[NSURL URLWithString:B_MENU_BG] placeholderImage:[UIImage imageNamed:@"v2menu"] options:SDWebImageProgressiveLoad];
}

- (void)fillCellWithModel:(CommonMenuModel *)model {
    self.dataArray = @[].mutableCopy;
    self.dataArray = model.titleArray;
    
    self.sectionHeaderView.mainTitleLab.text = model.bhmMenuName;
    
//    if ([TTUserModel sharedObject].token.length > 0) {
        self.sectionHeaderView.subTitleLab.text = [NSString stringWithFormat:@"¥%@/桌 %ld道菜",[Utilities changeDoubleToString:model.bhmMenuPrice],model.titleArray.count];
        
//    } else {
//        self.sectionHeaderView.subTitleLab.text = [NSString stringWithFormat:@"登录后查看补贴价 %ld道菜",model.titleArray.count];
//
//    }

    [self.tableview reloadData];
}

- (void)initView {
    
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;    
    _tableview.showsHorizontalScrollIndicator = NO;
    _tableview.showsVerticalScrollIndicator = NO;
    
    _tableview.estimatedSectionHeaderHeight = 0;
    _tableview.estimatedSectionFooterHeight = 0;
    _tableview.estimatedRowHeight = 0;
    
    [_tableview registerNib:[UINib nibWithNibName:@"MenuDetailListCell" bundle:nil] forCellReuseIdentifier:@"MenuDetailListCellID"];
    
    [self.tableview reloadData];
}

#pragma mark UITableviewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    return self.dataArray.count;
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 30;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 70;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    return self.sectionHeaderView;;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MenuDetailListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuDetailListCellID"];
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
//    [cell fillCellWithModel:self.dataArray[indexPath.section].goodsList[indexPath.row]];
    NSString *title = self.dataArray[indexPath.row];
    cell.itemTitleLab.text = title;
    return cell;
}


- (MenuSectionHeader *)sectionHeaderView {
    if (!_sectionHeaderView) {
        _sectionHeaderView =  [[NSBundle mainBundle] loadNibNamed:@"MenuSectionHeader"owner:nil options:nil].firstObject;
    }
    return _sectionHeaderView;
}

@end
